﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace Framework.Common.Paged
{
    [DataContract]
    public class PagedParam<TQueryDto>
    {
        /// <summary>
        /// 查询对象
        /// </summary>
        [DataMember]
        public TQueryDto QueryDto { get; set; }
        /// <summary>
        /// 分页对象
        /// </summary>
        [DataMember]
        public PageDto PageDto { get; set; }
        /// <summary>
        /// 排序集合
        /// </summary>
        [DataMember]
        public IList<OrderDto> OrderListDto { get; set; }

        public PagedParam()
        {
            //QueryDto = new TQueryDto();
            //PageDto = new PageDto();
            //OrderListDto = new List<OrderDto>();
        }

        public PagedParam(TQueryDto queryDto, PageDto pageDto, IList<OrderDto> orderListDto)
        {
            this.PageDto = pageDto;
            this.OrderListDto = orderListDto;
            this.QueryDto = queryDto;
        }
        public PagedParam(TQueryDto queryDto, PageDto pageDto, OrderDto orderDto)
        {
            this.PageDto = pageDto;
            this.OrderListDto = new List<OrderDto>();
            this.OrderListDto.Add(orderDto);
            this.QueryDto = queryDto;
        }
        public List<KeyValuePair<string, string>> SortField
        {
            get
            {
                var dictList = new List<KeyValuePair<string, string>>();
                if (OrderListDto != null && OrderListDto.Any())
                {
                    dictList.AddRange(OrderListDto.Select(item => new KeyValuePair<string, string>(item.OrderField, item.OrderSort)));
                }
                return dictList;
            }
            private set { }
        }
    }
}

